package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressMapper {

    /**
     * 新增地址信息
     * @param addressBook
     */
    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
            "VALUE(#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault}) ")
    void add(AddressBook addressBook);

    /**
     * 条件查询地址列表
     * @param addressBook
     * @return
     */
    List<AddressBook> getAddressByCondition(AddressBook addressBook);

    /**
     * 根据id查询用户地址
     * @param id
     * @return
     */
    @Select("select id, user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default " +
            "from address_book where id = #{id}")
    AddressBook getAddressById(Long id);

    /**
     * 修改用户地址信息
     * @param addressBook
     * @return
     */
    void upadate(AddressBook addressBook);

    /**
     * 根据id删除地址
     * @param id
     * @return
     */
    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);
}
